﻿using System;
using UnityEngine;
using System.ByteBuffer;
using gameplatform;
using SimpleJson;
using WindowsFormsApplication2;
using info;
using System.Collections;
using System.Collections.Generic;
using Zjh;
using evt;
namespace tools{
public class ByteFactory {

	public static byte[] makeByte(int head,object data){

		ByteBuffer bytes = new ByteBuffer ();
		ByteBuffer buffer = new ByteBuffer ();
		

			switch( head ){
						//登陆
				case 100101:
							string[] hash = data as string[];
							bytes.PushString (hash [0]);
							UserInfo.OpenID = hash [0];
							bytes.PushString (hash [1]);
							bytes.PushInt (int.Parse (hash [2]));
							bytes.PushString (hash [3]);
							UserInfo.headUrl = hash [3];
							bytes.PushString (hash [0]);
							bytes.PushString (hash [0]);
							bytes.PushString (hash [0]);
							bytes.PushString (hash [0]);
									
							break;

						//聊天
						case 102101:
							Chat.ReqTextChatMsg chat = new Chat.ReqTextChatMsg ();
							chat.content = data as string;
							chat.write (bytes);
							break;
							//语音
						case 102102:
							Chat.ReqVoiceChatMsg voice = new Chat.ReqVoiceChatMsg ();
							voice.content = data as string;
							voice.write (bytes);
							break;
						//心跳包
						case 100150:

							break;
						//请求开房
						case 621105:
							ReqCreateRoomMsg req = new ReqCreateRoomMsg ();
							int[] arr = data as int[];
							req.rounds = arr [0];
							req.players = arr [1];
							req.write (bytes);
							bytes.PushInt (arr [2]);
							break;
							//请求进房
						case 621102:
							ReqEnterRoomMsg enterRoom = new ReqEnterRoomMsg ();
							enterRoom.roomId = int.Parse(data as string);
							enterRoom.write (bytes);
							break;
							//请求准备
						case 621107:
							//ReqReadyMsg readyMsg = new ReqReadyMsg ();
							//readyMsg.write (bytes);
							break;
						case 621109:
							ReqBetMsg betMsg = new ReqBetMsg ();
							int[] cedit = data as int[];
							betMsg.cedit = cedit [0];
							betMsg.write (bytes);
							break;
						case 621111:
							ReqSeeCardMsg seemsg = new ReqSeeCardMsg ();
							seemsg.write (bytes);
							break;
						case 621113:
							ReqDiscardMsg DisCardMsg = new ReqDiscardMsg ();
							DisCardMsg.write (bytes);
							break;
						case 621115:
							thirteen.ReqVersusMsg VersusMsg = new thirteen.ReqVersusMsg ();
							List<Combination> resultList = data as List<Combination>;
							VersusMsg.tailCardsType = resultList [0].Type;
							VersusMsg.tailCards = resultList [0].getValue ();
							VersusMsg.midCardsType = resultList [1].Type;
							VersusMsg.midCards = resultList [1].getValue ();
							VersusMsg.headCardsType = resultList [2].Type;
							VersusMsg.headCards = resultList [2].getValue ();
							VersusMsg.write (bytes);
							break;
						case 621101:
							thirteen.ReqDisbandRoomMsg DisbandMsg = new thirteen.ReqDisbandRoomMsg ();
							DisbandMsg.write (bytes);
							break;
						case 621103:
							thirteen.ReqConfirmDisbandRoomMsg confirmMsg = new thirteen.ReqConfirmDisbandRoomMsg ();
							confirmMsg.yes = (int)data;
							confirmMsg.write (bytes);
							break;
						case 621117:
							ReqLeaveRoomMsg leaveMsg = new ReqLeaveRoomMsg ();
							leaveMsg.write (bytes);
							break;
							default:break;
				
			}
			buffer.PushInt (bytes.Length+8);
			buffer.PushInt (ByteTools.msgKey(bytes.Length+8));
			buffer.PushInt (head);
			buffer.PushByteArray(bytes.ToByteArray());
			//GSocket.byteList.Add (buffer.ToByteArray ());
			return buffer.ToByteArray();
		}
	}
}
